package com.voice.server.controller.device;

import com.voice.server.input.DeviceQuery;
import com.voice.server.output.DeviceInfo;
import com.voice.server.service.DeviceService;
import com.wangjiacai.utils.output.ResultVO;
import com.wangjiacai.utils.utils.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/device/root")
public class DeviceRootController {

    @Autowired
    private DeviceService deviceService;

    @GetMapping("/num")
    public ResultVO getDeviceListNum(DeviceQuery deviceQuery, Integer size){
        long totalNum=deviceService.getDeviceListNum(deviceQuery);
        return ResultVOUtil.success((long)Math.ceil(totalNum/(double)size));
    }

    @GetMapping
    public ResultVO getDeviceList(DeviceQuery deviceQuery, Pageable pageable){
        List<DeviceInfo> list=deviceService.getDeviceList(deviceQuery,pageable);
        return ResultVOUtil.success(list);
    }

    @PostMapping("/ota")
    public ResultVO postOTA(MultipartFile file,String ids){
       return ResultVOUtil.success();
    }
}
